<?php
require_once 'lib/Request.php';
require_once 'lib/CException.php';

class Controller{

	protected $_output = array();

	protected static $_render;

	protected static $_request;

	protected static $_config;

	public static function init($config, $render){
		self::setConfig($config);
		self::setRender($render);
	}

	public static function setConfig($config){
		self::$_config = $config;	
	}

	public static function getConfig(){
		return self::$_config;
	}

	public static function setRender( $render ){
		self::$_render = $render;	
	}

	/**
	 * 返回页面
	 */
	public static function getRender(){

		if( self::getRequest()->notSupportBrowser() ){
			throw new CException('对不起，本站不支持不安全的低版本IE浏览器,请到微软官方去升级到IE9以上!',0);
		}

		return self::$_render;
	}

	/**
	 * 统一头尾的布局
	 *
	 */
	public function render(){

		if( self::getRequest()->notSupportBrowser() ){
			throw new CException('对不起，本站不支持不安全的低版本IE浏览器,请到微软官方去升级到IE9以上!',0);
		}

		include self::$_config['application']['views']."/layout/header.php";
		include self::$_render;
		include self::$_config['application']['views']."/layout/footer.php";

	}

	public static function getRequest(){
		return Request::getInstance();
	}

	public function getUser(){
		require_once 'services/UserService.php';
		$user = new UserService();
		return $user->getUserByCookie();
	}

}
